#{extends 'main.html' /}
<br/>
<head>
    <script type="text/javascript">
        function swap(b, p){ //document.getElementById('b').disabled=true;
            document.getElementById(b).style.display = (document.getElementById(b).style.display == "none") ? "block" : "none";
            document.getElementById(p).src = (document.getElementById(b).style.display == "block") ? "/public/images/minus.gif" : "/public/images/plus.gif";
            
        }
        
        function getRadioCheckedValue(radio_name){
			var oRadio = document.getElementsByName(radio_name);
            for (var i = 0; i < oRadio.length; i++) {
                if (oRadio[i].checked) {
                    return oRadio[i].value;
                }
                
            }
        return '';
        }
		function disable()
		{
			var radioIndex = getRadioCheckedValue('storyId');
			var radioButtons = document.getElementsByName('storyId');
			alert(radioIndex>0);
			if (radioIndex > 0) {
				document.getElementById('sprintId').disabled = true;
			}
			else
			{
				if (document.getElementById('sprintId').selectedIndex > 0) {
           			 for (var i = 0; i < radioButtons.length; i++) {
					 	radioButtons[i].disabled = true;
					 }
                }
				else
				{
					for (var i = 0; i < radioButtons.length; i++) {
					 	radioButtons[i].disabled =false;
					 }
					 	document.getElementById('sprintId').disabled = false;

				}
			}
			
		}
    </script>
</head>
#{form @Tasks.renderCreateTask(description,details,priority,typeId,statusId,dependOn,eventsId,project.getEntityId(),storyId,sprintId), class:'jqtransform', id:'myForm'}<H2><a style ="color:#400040;" href = "@{Projects.showProject((Long)project.getEntityId())}">${project.name}</a> > <a style ="color:#400040;" href = "@{Tasks.showAllProjectTasks((Long)project.getEntityId())}">Tasks</a> > Create Task</H2>
<hr/>Summary
<sup>
    <FONT COLOR="#ff0000">
        *
    </FONT>
</sup>:
<br/>
<textarea class="validate[required,length[1,100]]" rows="2" cols="40" name = "description" id = "description">
</textarea>
<br/>
Description
<sup>
    <FONT COLOR="#ff0000">
        *
    </FONT>
</sup>:
<br/>
<textarea class="validate[required]" rows="5" cols="40" name = "details" id = "details">
</textarea>
<br/>
#{secure.check 'Set/edit priority of a task'}
Priority:
<br/>
<select name = "priority" id = "priority">
    #{list items:priorities, as:'priority'}<option value = "${priority}">${priority}<option> #{/list}
        </select>
        <br/>
        <br/>
        #{/secure.check} 
        Type:
        <br/>
        <select name = "typeId" id="typeId">
            #{list items:taskTypes, as:'taskType'}<option value = "${taskType.getEntityId()}">${taskType.type} <option>
                <br/>
                #{/list}
                </select>
                <br/>
                <br/>
                Status:
                <br/>
                <select name = "statusId" id = "statusId">
                    #{list items:taskStatuses, as:'taskStatus'}<option value = "${taskStatus.getEntityId()}">${taskStatus.status}<option> #{/list}
                        </select>
                        <br/>
                        <br/>
                        #{secure.check 'associate a task to a user story'}
                        #{if userStories}
                        <br/>
                        <img src="/public/images/minus.gif" id='y' onclick ="javascript:swap('x','y');"/>Associate to User Story:
                        <div  id ='x' style="width:700px;height:210px;overflow-y: scroll;word-wrap:break-word;">
                        <br/>
						<input name = "storyId" id = "storyId" type = "radio" checked="checked" value ="0L" onchange="javascript:disable();" />none
                        <br/>
                        <br/>
                        #{list items:userStories, as: 'story'} 
						<input name = "storyId" id = "storyId" type = "radio" value ="${story.getEntityId()}" onchange="javascript:disable();"/><!--	<option value ="${story.getEntityId()}">--> As a/an 
                        #{list items: story.appRoles, as: 'appRole'}
                        ${appRole.name},
                        #{/list}
                        ${story.story}
                        <br/>
                        <br/>
                       #{/list}
					   </div>
					   #{/if}
                        #{/secure.check}
                        <br/>
                        <br/>
                        #{secure.check 'Set/edit dependances between tasks'}
                        #{if tasks}<img src="/public/images/minus.gif" id='d' onclick ="javascript:swap('b','d');"/> Depends On Task(s):
                        <br/>
                        <br/>
                        <div id = 'b' style="width:700px;height:200px;overflow-y: scroll;word-wrap:break-word;">
                            #{list items:tasks, as:'task'}<input name = "dependOn" id = "dependOn" type = "checkbox" value = "${task.getEntityId()}"><a href="@{Tasks.showTask(task.getEntityId())}">${task.description}</a>
                            <br/>
                            <br/>
                            #{/list}
                        </div>
                        <br/>
                        <br/>
                        #{/if}
                        #{/secure.check}
                        #{secure.check 'Associate a task to a specific sprint in my project'}
                        #{if availableSprints}
                        Associate to Sprint:
                        <br/>
                        <select name="sprintId" id = "sprintId" onchange="javascript:disable();">
                            <option value ="0L" selected="selected">none</option>
                            #{list items:availableSprints, as: 'sprint'}
							<option value ="${sprint.getEntityId()}">${sprint.name}</option>
                            #{/list}
                        </select>
                        <br/>
                        <br/>
                        #{/if}
                        #{/secure.check}
                        <br/>
                        #{secure.check 'associate tasks to event'}
                        #{if availableEvents}<img src="/public/images/minus.gif" id='p' onclick ="javascript:swap('c','p');"/>Associate to Event(s):
                        <br/>
                        <div id = 'c' style="width:700px;height:200px;overflow-y: scroll;">
                            #{list items:availableEvents, as: 'event'}<input name = "eventsId" id = "eventsId" type = "checkbox" value = "${event.getEntityId()}" /><a href="@{Events.showEvent(event.getEntityId())}">${event.name}</a>
                            <br/>
                            <br/>
                            #{/list}
                        </div>
                        <br/>
                        <br/>
                        #{/if}
                        #{/secure.check}
                        <br/>
                        <input type="submit" name="submit" class="button" id="submit_btn" value="create" />
                        <br/>
                        #{/form}